import 'package:flutter/material.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/image_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/labor_hour.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/parts_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/repair_car_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/repair_order_info.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

//修理厂 已撤案
class RepairWithDrawn extends StatefulWidget {
  //{title}
  final Map<String, dynamic> arguments;

  const RepairWithDrawn({Key key, this.arguments}) : super(key: key);

  @override
  _RepairWithDrawnState createState() => _RepairWithDrawnState();
}

class _RepairWithDrawnState extends State<RepairWithDrawn>
    with SingleTickerProviderStateMixin {
  TabController _tabController; //tab控制器
  List<String> titleList = ["订单信息", "车辆信息", "图片信息"];
  List<String> orderInfo = [
    "订单编号",
    "订单时间",
    "推修来源",
    "车辆型号",
    "车辆牌号",
    "订单状态"
  ]; //訂單信息

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = new TabController(length: titleList.length, vsync: this);

    _tabController.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: YTStyle.bgColor,
      appBar: AppBar(
        elevation: 0.5,
        centerTitle: true,
        backgroundColor: Colors.white,
        title: Text(
          widget.arguments["title"] as String,
          style: TextStyle(
              color: Color(0xff323232),
              fontSize: setSp(18),
              fontWeight: FontWeight.w600),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
        bottom: TabBar(
          controller: _tabController,
          isScrollable: true,
          labelColor: YTTheme.theme,
          labelStyle:
              TextStyle(fontSize: setSp(17), fontWeight: FontWeight.w600),
          unselectedLabelColor: Color(0xff323232),
          unselectedLabelStyle:
              TextStyle(color: Colors.white, fontSize: setSp(17)),
          indicatorColor: YTTheme.theme,
          indicatorSize: TabBarIndicatorSize.label,
          tabs: titleList
              .asMap()
              .map((key, value) {
                return MapEntry(key, _tabItem(titleList[key]));
              })
              .values
              .toList(),
        ),
        leading: GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () {
            Navigator.pop(context);
          },
          child: Row(
            children: [
              Container(
                  margin: EdgeInsets.only(left: setWidth(15)),
                  width: setWidth(10),
                  height: setWidth(17),
                  child: Image.asset(
                    "assets/images/return.png",
                    fit: BoxFit.cover,
                  )),
            ],
          ),
        ),
        actions: [
          Container(
            margin: EdgeInsets.only(right: setWidth(15)),
            width: setWidth(10),
            height: setWidth(17),
          ),
        ],
      ),
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: SizedBox(
              height: setWidth(15),
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              padding: EdgeInsets.only(
                  left: setWidth(15),
                  right: setWidth(15),
                  bottom: setWidth(15)),
              color: Colors.white,
              child: _checkType(_tabController.index),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: setWidth(15),
            ),
          ),

          //配件信息
          SliverToBoxAdapter(
            child: PartsInfo(),
          ),
          SliverToBoxAdapter(
            child: SizedBox(
              height: setWidth(15),
            ),
          ),

          //工时信息
          SliverToBoxAdapter(
            child: LaborHour(),
          ),

          //结算信息
          SliverToBoxAdapter(
            child: Container(
                margin:
                    EdgeInsets.only(top: setWidth(15), bottom: setWidth(20)),
                child: autoMakersSettlement(
                    price: "600", serve: "600", sum: "1460.00")),
          ),
        ],
      ),
    );
  }

  Widget _tabItem(String title) {
    return Tab(text: title);
  }

  // ignore: missing_return
  Widget _checkType(int type) {
    switch (type) {
      case 0:
        return RepairOrderInfo(orderState: widget.arguments["title"] as String);
        break;
      case 1:
        return RepairCarInfo();
        break;
      case 2:
        return ImageListInfo();
        break;
    }
  }
}
